﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Unity.Test.Performance.timer
{

    #region eventargs
    public class TTimerEndedEventArgs
    {
        #region ctors
        public TTimerEndedEventArgs()
        {
            _CompletionTimeSpan = new TimeSpan();
        }
        public TTimerEndedEventArgs(TimeSpan completionTimeSpan)
        {
            _CompletionTimeSpan = new TimeSpan();
        }
        #endregion

        #region properties
        private TimeSpan _CompletionTimeSpan;
        public TimeSpan CompletionTimeSpan
        {
            get { return _CompletionTimeSpan; }
            set { _CompletionTimeSpan = value; }
        }
        #endregion
    }
    public class TTimerRunningEventArgs
    {
        #region ctors
        public TTimerRunningEventArgs()
        {
        }
        #endregion

        #region properties
        private double _CompletionRatio;
        public double CompletionRatio
        {
            get { return _CompletionRatio; }
            set { _CompletionRatio = value; }
        }

        private TimeSpan _RemainedTime;
        public TimeSpan RemainedTime
        {
            get { return _RemainedTime; }
            set { _RemainedTime = value; }
        }
        #endregion
    }

    #endregion

    #region delegates
    public delegate void DTimerRunningEventHandler(TTimerRunningEventArgs args);
    public delegate void DTimerEndedEventHandler(TTimerEndedEventArgs args);
    #endregion

    public class TTimerEvents
    {
        #region handlers
        private DTimerEndedEventHandler _TimerEndedEventHandler;
        private DTimerRunningEventHandler _TimerRunningEventHandler;
        #endregion

        #region events
        public event DTimerEndedEventHandler TimerEnded
        {
            add { _TimerEndedEventHandler += value; }
            remove { _TimerEndedEventHandler -= value; }
        }
        public event DTimerRunningEventHandler TimerRunning
        {
            add { _TimerRunningEventHandler += value; }
            remove { _TimerRunningEventHandler -= value; }
        }
        #endregion
        
        #region triggers
        public void OnTimerRunning(TTimerRunningEventArgs args)
        {
            if (_TimerRunningEventHandler != null)
                _TimerRunningEventHandler(args);
        }
        public void OnTimerEnded(TTimerEndedEventArgs args)
        {
            if (_TimerEndedEventHandler != null)
                _TimerEndedEventHandler(args);
        }
        #endregion
        
    }
}
